package com.whz.trycatch;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @Author: sinosoft
 * @Description:
 * @Date: Create in 16:02 2021/4/30
 * @Modified By:
 */
public class ReadFile {
    public static void main(String[] args) {
        ReadFile rf = new ReadFile();
        try {
            rf.read("Elvis.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void read(String filename) throws IOException {
        FileInputStream input = null;
        IOException readException = null;
        try {
            input = new FileInputStream(filename);
        } catch (IOException ex) {
            readException = ex;
        } finally {
            if(input != null){
                try {
                    input.close();
                } catch (IOException ex2) {
                    if(readException != null){
                        readException.addSuppressed(ex2);
                    }else{
                        readException = ex2;
                    }
                }
            }
            if(readException != null){
                throw readException;
            }
        }
    }
}
